//异或加密
function XorEncodeStr(message, key) {
  // console.log(message);
  const arr = [];
  var ml = message.length
  var kl = key.length
  for (let i = 0; i < ml; i++) {

    const  m = message.substr(i, 1);//parseInt(message.substr(i, 1), ml);

    
    const k = key.substr(parseInt(i%kl),1);//parseInt(key.substr(i, 1), kl);
   
    const asstr = k.charCodeAt() ^ m.charCodeAt()
    arr.push(String.fromCharCode(asstr));
  }
  return arr.join('');
}

//异或解密
function XorDecodeStr(message, key) {
  const arr = [];
  var ml = message.length
  var kl = key.length
  for (let i = 0; i < ml; i++) {
    const  m = message.substr(i, 1);
    // console.log(m);
    const k = key.substr(parseInt(i%kl),1);

    const asstr =  m.charCodeAt() ^ k.charCodeAt()
    // console.log(asstr,String.fromCharCode(asstr));
    arr.push(String.fromCharCode(asstr));
  }
  return arr.join('')
}

//格式化字符串
function strTojson(msg) {
  var  tt;
  try {
    tt = JSON.parse(msg);
  } catch(e) {
    console.log("json解析失败");
  }
  var res = JSON.stringify(tt,null,"\t");
  
  
  
  return res
}

function shijianchuo () {
    var tmp = new Date().getTime();
    
    // var strdate = tmp.toString() 
    // var date = strdate.substring(0,strdate.length-3);
    // return date+"000"
    return tmp
}

function Base64Encode(msg){
  // return window.btoa(msg)
  return Base64.encode(msg);
}


function Base64Decode(msg){

  // return window.atob(msg)
  return Base64.decode(msg);
}

function XorString(msg,key) {
  const bs = Base64Encode(msg);
  const xormsg = XorEncodeStr(bs,key);
  return xormsg;
}
